chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
    const audioElements = document.getElementsByTagName('audio');
    const videoElements = document.getElementsByTagName('video');

    function updateMediaElements(elements) {
        for (let element of elements) {
            switch(request.action) {
                case 'volume':
                    element.volume = request.value;
                    break;
                case 'speed':
                    element.playbackRate = request.value;
                    break;
            }
        }
    }

    updateMediaElements(audioElements);
    updateMediaElements(videoElements);
});
